﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.ReportSource;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Windows;
using System.IO;
using System.Reflection;
namespace UI.Desktop
{
    public partial class frmReporteHistorial : Form
    {
        public frmReporteHistorial()
        {
            InitializeComponent();
        }

        #region CB PACIENTE

        private void cbPaciente_Click(object sender, EventArgs e)
        {
            Business.Entities.Paciente pac = new Business.Entities.Paciente();
            DataSet dsPac = new DataSet();
            dsPac = pac.ObtenerListaPacientesHabilitados();
            ObtenerPacientes(dsPac);
        }

        private void ObtenerPacientes(DataSet dsPac)
        {
            cbPaciente.Text = "Seleccione el paciente";
            cbPaciente.DataSource = dsPac.Tables["Paciente"];
            cbPaciente.DisplayMember = dsPac.Tables["Paciente"].Columns[1].Caption.ToString();
        }

        #endregion

        #region BOTON EMITIR

        private void btnEmitir_Click(object sender, EventArgs e)
        {
            try
            {
                ReportDocument rpt = new ReportDocument();
                ReporteHistorial rh = new ReporteHistorial();

                string ruta = Path.Combine(Application.StartupPath, "ReporteHistorial.rpt");

                rpt.Load(ruta);
                Business.Entities.Paciente Pac = new Business.Entities.Paciente();
                DataSet dspac = new DataSet();
                string Concatenado = cbPaciente.Text.ToString();
                dspac = Pac.ObtenerListaPacientesConNombreApellido(Concatenado);
                string Id_Paciente = dspac.Tables["Paciente"].Rows[0][0].ToString();

                ///Aca comparo el Combobox para filtrar por Paciente
                ParameterFieldDefinitions crParameterFieldDefinitions;
                ParameterFieldDefinition crParameterFieldDefinition;
                ParameterValues crParameterValues = new ParameterValues();
                ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

                crParameterDiscreteValue.Value = Id_Paciente;
                crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields;
                crParameterFieldDefinition = crParameterFieldDefinitions["Paciente"];
                crParameterValues = crParameterFieldDefinition.CurrentValues;
                crParameterValues.Clear();
                crParameterValues.Add(crParameterDiscreteValue);
                crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

                rpt.SetDatabaseLogon("sa", "123");
                CRVReporteHistorial.ReportSource = rpt;
                CRVReporteHistorial.Refresh();
            }
            catch
            {
                MessageBox.Show("Por favor seleccione un Paciente", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        #endregion

        private void frmReporteHistorial_Load(object sender, EventArgs e)
        {

        }
    }
}   
    
